<template>
	<view class="shop-cart">
		<u-checkbox-group v-model="selectId" placement="column" @change="selectChange" v-if="list.length > 0">
			<view class="li" v-for="(item, index) in list" :key="index">
				<view class="li-top u-flex">
					<view class="li-left u-flex-center">
						<u-checkbox shape="circle" activeColor="#000000" :customStyle="{marginRight: '0px'}"
							:name="item.id">
						</u-checkbox>
					</view>
					<view class="product u-flex u-col-start" @click="jump(item)">
						<view class="product-img">
							<view class="stock u-flex-center u-col-center" v-if="item.productSpec.stock == 0">
								<view class="stock-text">缺货</view>
							</view>
							<u-image :src="item.product.cover_image" :showMenuByLongpress="false" width="200rpx"
								height="200rpx"></u-image>
						</view>
						<view class="product-info">
							<view class="name">{{item.product.name}}</view>
							<view class="spec">
								{{item.productSpec.spec_name}}{{item.productSpec.notes?`[${item.productSpec.notes}]`:''}}
							</view>
							<view class="delivery-time">{{item.delivery_time}}</view>
							<view class="bottom u-flex-between u-col-end">
								<view class="bottom-left">
									<view class="price-content u-flex u-col-end">
										<view class="price u-flex u-col-end">
											<view class="price-icon">￥</view>{{item.productSpec.price}}
										</view>
										<view class="origin-price">￥{{item.productSpec.original_price}}</view>
									</view>
								</view>
								<view class="counter u-flex">
									<view class="icon u-flex-center"
										@click.stop="$emit('numberChange',{type:1,key:index})">
										<u-icon name="trash" color="#9d9d9d" size="12" v-if="item.number == 1"></u-icon>
										<view class="subtract" v-else>-</view>
									</view>
									<view class="number">{{item.number}}</view>
									<view class="icon" @click.stop="$emit('numberChange',{type:2,key:index})">+</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="total u-flex-end">小计：<view class="money u-flex u-col-end">
						<view class="icon">￥</view>{{(item.productSpec.price * item.number).toFixed(2)}}
					</view>
				</view>
			</view>
		</u-checkbox-group>
		<empty v-if="list.length == 0"></empty>
	</view>
</template>
<script>
	import empty from './empty.vue'
	export default {
		components: {
			empty,
		},
		name: "product-list",
		data() {
			return {
				selectId: [],
			};
		},
		// 此处定义传入的参数
		props: {
			list: {
				type: Array,
				default: (() => {
					return [];
				})
			}
		},
		mounted() {},
		methods: {
			initData(e) {
				this.selectId = e;
			},
			// 选择购物车中商品
			selectChange(e) {
				this.selectId = e;
				this.$emit('change', e)
			},
			jump(e) {
				if (e.product_type == 3) { // 秒杀商品
					var url = '/subPackages/seckillProduct/detail?seckill_id=' + e.seckill_id;
				} else {
					var url = '/subPackages/product/product-detail?product_id=' + e.product_id;
				}
				this.$navigateTo(url);
			}
		}
	}
</script>
<style lang="scss" scoped>
	.li {
		width: 100%;
		background-color: #FFFFFF;
		border-radius: 14rpx;
		margin-top: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;

		.li-top {

			.li-left {
				width: 80rpx;
			}

			.product {
				flex: 1;

				.product-img {
					position: relative;

					.stock {
						width: 100%;
						height: 100%;
						position: absolute;
						top: 0;
						left: 0;
						background-color: rgba(0, 0, 0, 0.5);
						z-index: 99;

						.stock-text {
							width: 88rpx;
							height: 48rpx;
							border: 2rpx solid #FFFFFF;
							font-size: 24rpx;
							color: #FFFFFF;
							text-align: center;
							line-height: 48rpx;
						}
					}
				}

				.product-info {
					flex: 1;
					padding: 10rpx;
					box-sizing: border-box;

					.name {
						width: 100%;
						box-sizing: border-box;
						font-size: 24rpx;
						font-weight: 700;
						color: #2b2b2b;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.spec {
						font-size: 24rpx;
						line-height: 50rpx;
						color: #8b8b8b;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;
					}

					.delivery-time {
						font-size: 24rpx;
						color: #515151;
						line-height: 50rpx;
					}

					.bottom {
						height: 86rpx;

						.bottom-left {

							.cut-price {
								height: 50rpx;
								font-size: 22rpx;
								color: $base-price-color;
							}

							.price-content {

								.price {
									font-weight: 800;
									line-height: 1;
									font-size: 26rpx;
									color: $base-price-color;

									.price-icon {
										font-size: 20rpx;
									}
								}

								.origin-price {
									line-height: 1;
									padding-left: 10rpx;
									text-decoration: line-through;
									font-size: 20rpx;
									color: #999999;
								}
							}
						}

						.counter {
							border-radius: 50rpx;
							border: 1rpx solid #EFEFEF;
							text-align: center;
							height: 50rpx;

							.icon {
								font-size: 30rpx;
								width: 50rpx;
								height: 50rpx;
								line-height: 50rpx;
							}

							.number {
								font-size: 22rpx;
								width: 50rpx;
								height: 50rpx;
								line-height: 50rpx;
							}
						}
					}
				}
			}
		}

		.total {
			margin-top: 20rpx;
			border-top: 1rpx solid #f8f8f8;
			padding: 20rpx 10rpx 10rpx 0;
			font-size: 22rpx;
			color: #747474;
			text-align: right;

			.money {
				font-size: 26rpx;
				font-weight: 800;
				color: $base-price-color;
				line-height: 1;

				.icon {
					line-height: 1;
					font-size: 20rpx;
				}
			}
		}
	}
</style>